package com.copa.l1768;

/**
 * @author copa
 * @createDate 2022-09-01 09:48
 * @function 一次遍历法
 */
public class Test1 {

    public String mergeAlternately(String word1, String word2) {
        StringBuilder sb = new StringBuilder();
        int strLength1 = word1.length();
        int strLength2 = word2.length();

        for (int i = 0; i < Math.min(strLength1, strLength2); i++) {
            sb.append(word1.charAt(i));
            sb.append(word2.charAt(i));
        }
        sb.append(strLength1 > strLength2 ? word1.substring(strLength2) : word2.substring(strLength1));

        return sb.toString();
    }

    public static void main(String[] args) {
        String word1 = "abc";
        String word2 = "efgh";
        System.out.println(new Test1().mergeAlternately(word1, word2));
    }
}
